# encoding:utf-8
import requests
import csv

# account-core 上执行人车绑定接口
# 若要删除人车关系，则路径变更为:http://127.0.0.1:18081/v2/relation/delete
# 联调
# url = "http://10.2.1.54:18081/v2/relation/inner/set"
# 预生产
url = "http://10.123.48.14:18081/v2/relation/inner/set"
headers = {
    'Content-Type': "application/json",
    'CompanyID': "1"
}

with open("tce_bind_car.csv", "w") as csvfile:
   # writer.writerow(["appid","phone", "userid", "din", "vin"])
    writer = csv.writer(csvfile)
    # 输出导入的人车关系表格title
    writer.writerow(["appid", "phone", "userid", "din", "vin"])
    # userid 注意这里 range 包含左边的数，但不包含右边的
    list1 = range(144115205374726865, 144115205374726866)
    # din
    list2 = range(144115205311837562, 144115205311837563)
    # vin码末尾字符串
    vinFront = "TESTVIN00000"
    # vin码末尾字符串
    list3 = range(10001, 20000)
    # phone number
    list4 = range(13539880025, 13539880030)
    for (i1, i2, i3, i4) in zip(list1, list2, list3, list4):
        print(i1, i2, vinFront + str(i3))
        payload = "{\"companyId\":\"1\", \"id\":\"" + str(i1) + "\",\"id2\":\"" + str(i2) + "\",\"data\": {\"ownerFlag\": true," \
            + "\"carNumber\": \"" + vinFront+str(i3) + "\"," \
            + "\"owner\": \"测试用户\"," \
            + "\"reseller\": {" \
            + "\"resellerProvince\": \"广东省\"," \
            + "\"resellerCity\": \"广州市\"," \
            + "\"resellerName\": \"广州广蔚新能源汽车销售有限公司" + str(i2) + "\"" \
            + "}," \
            + "\"updateTime\": \"1582596866119\"," \
            + "\"plateNumber\": \"桂B12312\"," \
            + "\"engineId\": \"12345678\"" \
            + "}}"
        print(payload)
        response = requests.request(
            "POST", url, data=payload.encode('utf-8'), headers=headers)
        print(str(response.content))
        writer.writerow(["1", str(i4), str(i1), str(i2), vinFront + str(i3)])
